package org.agridata.akvisualization.config;

import com.github.xiaoymin.knife4j.spring.extension.OpenApiExtensionResolver;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

/**
 * @author: yxc
 * @date: 2024/1/27 14:01
 * @Description: swagger配置
 */
@Configuration
@Slf4j
@EnableSwagger2WebMvc
public class Knfie4jConfiguration {
    /**
     * 分组名称
     */
    private String groupName = "product";


    @Autowired
    private OpenApiExtensionResolver openApiExtensionResolver;

    @Bean
    public Docket docket() {
        String groupName = "1.0.0";
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .host("localhost")
                .apiInfo(apiInfo())
                .groupName(groupName)
                .select()
//                .apis(RequestHandlerSelectors.basePackage("【重要】指定Controller包路径"))
                .paths(PathSelectors.any())
                .build()
                .extensions(openApiExtensionResolver.buildExtensions(groupName));
        return docket;
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("安康可视化后台管理系统-API文档")
                .description("开发对接文档")
                .termsOfServiceUrl("")
                .contact(new Contact("大哈拉鱼胖胖", "", ""))
                .version("V1.0.1")
                .build();
    }
}
